<template>
	<div class="truck-info-main-box">
		<div class="box-1">
			<div class="box-1-info">
        <div>
          <div style="width: 95px;height: 95px;">
            <img 
              v-if="img1 == ''" 
              @click="addImg(5)"
              style="width: 100%;height: 100%;" 
              src="../../../assets/images/carinfologo_11.png" />
            <el-image
              v-else
              style="width: 100%;height: 100%;"
              fit="cover"
              :src="img1"
              :preview-src-list="imgs"
            ></el-image>
          </div>
          <div class="img-title">
            车头侧45度
          </div>
        </div>
			</div>
			<div class="box-1-info">
        <div>
          <div style="width: 95px;height: 95px;">
            <img 
              v-if="img2 == ''" 
              @click="addImg(2)"
              style="width: 100%;height: 100%;" 
              src="../../../assets/images/carinfologo_5.png" />
            <el-image
              v-else
              style="width: 100%;height: 100%;"
              fit="cover"
              :src="img2"
              :preview-src-list="imgs"
            ></el-image>
          </div>
          <div class="img-title">
            整车铭牌
          </div>
        </div>
			</div>
			<div class="box-1-info">
        <div>
          <div style="width: 95px;height: 95px;">
            <img 
              v-if="img3 == ''" 
              @click="addImg(8)"
              style="width: 100%;height: 100%;" 
              src="../../../assets/images/carinfologo_7.png" />
            <el-image
              v-else
              style="width: 100%;height: 100%;"
              fit="cover"
              :src="img3"
              :preview-src-list="imgs"
            ></el-image>
          </div>
          <div class="img-title">
            驾驶证正本
          </div>
        </div>
			</div>
      <div class="box-1-btn" @click="showMoreImg">
        <img src="../../../assets/images/morepic.svg" />
      </div>
		</div>
		<div class="box-2">
			<div style="font-size: 16px;">
				<span>
					<img 
						style="position: relative;top: 4px;"
						width="20" 
						src="../../../assets/images/pen.svg" />
				</span>
				<span style="margin-left: 8px;">自编号：</span>
				<span style="display: inline-block;width: 150px;">{{info.selfNumbering}}</span>
				<span v-if="info.status == 0">
					<img 
						style="position: relative;top: 3px;float: right;"
						width="77" 
						src="../../../assets/images/picNeed.svg" />
				</span>
			</div>
			<div style="margin-top: 9px;font-size: 16px;">
				<span>
					<img 
						style="position: relative;top: 4px;"
						width="20" 
						src="../../../assets/images/pen.svg" />
				</span>
				<span style="margin-left: 8px;letter-spacing: 1em;">车</span>
				<span>型：</span>
				<span style="display: inline-block;width: 240px;">{{info.carType}}</span>
			</div>
			<div style="font-size: 12px;">
				<div style="margin-top: 9px;height: 17;line-height: 17px;">
					<span>实际使用单位：</span>
					<span style="display: inline-block;width: 200px;">{{info.actualUser}}</span>
				</div>
				<div style="margin-top: 9px;height: 17;line-height: 17px;">
					<span>品牌车型：</span>
					<span style="display: inline-block;width: 200px;">{{info.model}}</span>
				</div>
				<div style="margin-top: 9px;height: 17;line-height: 17px;">
					<span>车辆识别代码：</span>
					<span style="display: inline-block;width: 200px;">{{info.vin}}</span>
				</div>
				<div style="margin-top: 9px;height: 17;line-height: 17px;">
					<span>年检日期：</span>
					<span style="display: inline-block;width: 200px;">{{info.issueDate}}</span>
					<span 
            @click="gotoBasicInfo"
						style="display: inline-block;height: 17px;width: 67px;float: right;cursor: pointer;">
						<img width="67" src="../../../assets/images/truckInfo.svg" />
					</span>
				</div>
			</div>
		</div>
		<div class="box-3">
			<div class="box-3-head">
				<span style="margin-top: 100px;">功能</span>
			</div>
			<div class="box-3-body">
				<div>
					<div
						style="display: inline;"
						class="box-3-icon"
						>
						<img src="../../../assets/images/qianyi.svg" />
					</div>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/dangan.svg" />
					</span>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/jilu.svg" />
					</span>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/chakanren.svg" />
					</span>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/jihua.svg" />
					</span>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/guihua.svg" />
					</span>
				</div>
				<div style="margin-top: 25px;">
					<div
						style="display: inline;"
						class="box-3-icon"
						>
						<img src="../../../assets/images/gps.svg" />
					</div>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/chengzhong.svg" />
					</span>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/jiankong.svg" />
					</span>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/obd.svg" />
					</span>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/plc.svg" />
					</span>
					<span
						class="box-3-icon"
						>
						<img src="../../../assets/images/youhao.svg" />
					</span>
				</div>
				<div style="margin-top: 25px;">
					<div
						style="display: inline;"
						class="box-3-icon"
						>
						<img src="../../../assets/images/gps.svg" />
					</div>
				</div>
			</div>
		</div>
    <input type="file" style="display: none;" id="uploadFile" @change="uploadImg" />
	</div>
</template>

<script>
  import {getCarInfo} from '@/api/workspace/work_order'
  import {uploadTruckImg} from '@/api/workspace/uploadFile'
  import $ from 'jquery'
	export default {
		props:{
			data:Object,
			carId:Number
		},
		data(){
			return{
				info:{},
        img1:'',
        img2:'',
        img3:'',
        imgs:[],
        type:-1
			}
		},
		created() {
			this.load();
		},
		methods:{
			load:function(){
        var that = this;
        // console.log(that.data);
        if(typeof that.data.carInfoId == 'undefined'){
          
          that.$router.push({
            path:'/main/settlement/pick_info',
            query:{
              id:that.$route.query.id
            }
          })
          return;
        }
        getCarInfo({id:that.data.carInfoId}).then(response => {
          var _data = response.data;
          // console.log(_data)
          if(_data.status == 200){
            var imgs = _data.data.img;
            var imgUrls = [];
            for(var img of imgs) {
              if(img.type == 5) {
                that.img1 = img.imgUrl;
              }else if(img.type == 2){
                that.img2 = img.imgUrl;
              }else if(img.type == 8){
                that.img3 = img.imgUrl;
              }
              imgUrls.push(img.imgUrl);
            }
            that.info = _data.data;
            that.imgs = imgUrls;
          }else {
            that.$message({
              message:_data.msg,
              showClose:true,
              type:'error',
              offset:'100'
            })
          }
        }).catch(error => {
          alert('网络错误');
          console.log(error)
        })
			},
      uploadImg:function(e) {
        var that = this;
        var data = new FormData();
        data.append('file',e.target.files[0]);
        data.append('type',this.type);
        uploadTruckImg(data,this.info.id).then(response => {
          var _data = response.data;
            // console.log(_data);
          if(_data.code == 200) {
            if(that.type == 5) {
              that.img1 = _data.data;
            }else if(that.type == 8) {
              this.img3 = _data.data;
            }else if(that.type == 2) {
              this.img2 = _data.data;
            }
            that.imgs.push(_data.data);
            that.$message.success('上传成功');
          }else {
            that.$message.error(_data.message);
          }
        }).catch(error => {
          that.$message.error('发生错误');
          console.log(error);
        })
      },
      addImg:function(type) {
        this.type = type;
        $('#uploadFile').click();
      },
      gotoBasicInfo:function() {
        this.$emit('toBasicInfo');
      },
      showMoreImg:function () {
        this.$emit('toAllImages');
      }
		}
	}
</script>

<style lang="css" scoped>
	.truck-info-main-box {
		margin-left: -1px;
	}
	.box-1 {
		padding: 0 5px;
		height: 95px;
    overflow: hidden;
	}
	.box-1>.box-1-info {
		width: 95px;
		height: 95px;
		border-radius: 6px;
		overflow: hidden;
		float: left;
    margin-right: 10px;
    cursor: pointer;
	}
	.box-1-btn {
		height: 95px;
		/* margin-left: 10px; */
		cursor: pointer;
	}
  .img-title {
    position: relative;
    top: -30px;
    height: 30px;
    border-radius: 0 0 6px 6px;
    background-color: rgba(0,0,0,0.5);
    color: white;
    font-size: 12px;
    line-height: 30px;
    text-align: center;
  }
	.box-2 {  
		border-radius: 6px;
		background-color: rgba(255, 255, 255, 1);
		box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.2);
		margin-top: 9px;
		padding: 10px;
		color: rgba(51, 51, 51, 1);
	}
	.box-3 {
		border-radius: 10px;
		background-color: rgba(255, 255, 255, 1);
		box-shadow: 0px 0px 4px 0px rgba(0, 0, 0, 0.2);
		margin-top: 9px;
		width: 359px;
	}
	.box-3 .box-3-head {
		height: 28px;
		border-radius: 10px 10px 0 0;
		background-color: rgba(246, 247, 248, 1);
		color: rgba(51, 51, 51, 1);
		font-size: 16px;
		font-family: PingFangSC-Medium;
		font-weight: 550;
		padding: 13px 10px;
	}
	.box-3 .box-3-body {
		padding: 12px 10px;
	}
	.box-3-body span {
		margin-left: 15px;
	}
	.box-3-icon {
		cursor: pointer;
	}
</style>
